package com.slimbloody.controller;

import com.github.benmanes.caffeine.cache.Cache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/cache")
public class CacheController {
  @Autowired
  @Qualifier("userTcmQualityCache")
  private Cache<String, Map<String, BigDecimal>> cache;

  @PostMapping("/put")
  public void put() {
    Map<String, BigDecimal> map1 = new HashMap<>();
    map1.put("1", BigDecimal.ONE);
    map1.put("2", BigDecimal.ZERO);

    Map<String, BigDecimal> map2 = new HashMap<>();
    map2.put("1", new BigDecimal(10));
    map2.put("2", new BigDecimal(20));

    cache.put("map1", map1);
    cache.put("map2", map2);
  }

  @PostMapping("/get")
  public void get() {
    Map<String, BigDecimal> stringBigDecimalMap = cache.getIfPresent("map1");
    System.out.println();
  }
}
